<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="摄像头编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="number">
              <a-input v-model="model.number" placeholder="请输入摄像头编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="IP地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ip">
              <a-input v-model="model.ip" placeholder="请输入IP地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userName">
              <a-input v-model="model.userName" placeholder="请输入用户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="password">
              <a-input v-model="model.password" placeholder="请输入密码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="流媒体地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rtspAddress">
              <a-input v-model="model.rtspAddress" placeholder="请输入流媒体地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="安装区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="regionId">
              <a-textarea v-model="model.regionId" rows="4" placeholder="请输入安装区域" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="音频地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="videoUrl">
              <a-textarea v-model="model.videoUrl" rows="4" placeholder="请输入音频地址" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="镜头类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cameraType">
              <j-dict-select-tag type="list" v-model="model.cameraType" dictCode="camera_type" placeholder="请选择镜头类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="设备数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cameraNum">
              <a-input-number v-model="model.cameraNum" placeholder="请输入设备数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="摄像机规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spec">
              <a-input v-model="model.spec" placeholder="请输入摄像机规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="摄像机型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="model">
              <a-input v-model="model.model" placeholder="请输入摄像机型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="预定智能" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="intelligence">
              <a-input v-model="model.intelligence" placeholder="请输入预定智能"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="补光灯数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lightNum">
              <a-input v-model="model.lightNum" placeholder="请输入补光灯数量"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'YksCameraForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        action:'',
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 12 },
        },
        confirmLoading: false,
        validatorRules: {
           number: [
              { required: true, message: '请输入摄像头编号!'},
           ],
           name: [
              { required: true, message: '请输入名称!'},
           ],
        },
        url: {
          add: "/dev/yksCamera/add",
          edit: "/dev/yksCamera/edit",
          queryById: "/dev/yksCamera/queryById"
        },
        currentEquipmentId:'',
        equipmentProjectcode:''
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.action = "add"
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        if (this.action=="add") {
          this.model.equipmentId = this.currentEquipmentId
          this.model.equipmentProjectcode=this.equipmentProjectcode
        }
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>